// global variables //
aeroui.TIMER = 0;
aeroui.SPEED = 100;
aeroui.DISABLED = [];
//var WRAPPER = 'content';


// build/show the dialog box, populate the data and call the fadeDialog function //
/**
 * @param title 是指window的title
 * @param _url 是指要用于ajax请求的_url
 * @param type 是window的类型
 * @param autohide 是否自动消失
 * @param successCallBack 成功之后的回调
 * @param width dialog的width 默认为window的width/3
 * @param heigth dialog的height 默认为window的height/3
 */
function showDialog(title,_url,_width,_height,successCallBack,type,flag,callBack) {
  if(!type) {
    type = 'error';
  }
    var dialog = document.getElementById('dialog');
    var dialogheader = document.getElementById('dialog-header');
    var dialogtitle = document.getElementById('dialog-title');
    var dialogclose = document.getElementById('dialog-close');
    var dialogcontent = document.getElementById('dialog-content');
    var dialogmask = document.getElementById('dialog-mask');
    dialogmask.style.visibility = "visible";
    dialogmask.style.height = document.body.scrollHeight + 'px';
    dialog.style.visibility = "visible";
    // dialogclose.setAttribute('onclick','hideDialog()');
    
    dialogclose.onclick = function(){
    	hideDialog();
    	if(flag) {
    		callBack();
    	}	
    }
    //dialogclose.onclick = hideDialog;

  // 清空div的内容
  dialogtitle.innerHTML = '';
  dialogcontent.innerHTML = '';
  /**
	 * 把要用的div设置为可见
	 *************************************/
  if(dialog.style.display == 'none'){
  	dialog.style.display = '';
  }
  if(dialogmask.style.display == 'none'){
  	dialogmask.style.display = '';
  }
  var _left = window.screen.width / 2 - _width / 2;
  var _top = window.screen.height / 3 - _height / 2;
 _top = _top + document.body.scrollTop;
  dialog.style.top =  _top  + "px";
  dialog.style.left = _left + "px";
  dialogheader.className = type + "header";
  dialogheader.style.width = _width  + 'px';
  dialogtitle.innerHTML = title;
  dialogcontent.className = type;
  dialogcontent.style.width = _width  + 'px';
  dialogcontent.style.height = _height  + 'px';
  // 为window的加载提供进度信息
  dialogcontent.style.backgroundImage = 'url("common/js/dialog/images/blue-loading.gif")';
  dialogcontent.style.backgroundPosition = 'center';
  dialogcontent.style.backgroundRepeat = 'no-repeat';
  /*
   * ajax请求得到html
   */
   $.ajax({
   		url : encodeURI(_url),
   		type : 'POST',
   		cache : false,
   		success : function(result){
			if(result != null ){
	   			var _content = document.getElementById('dialog-content');
				/*
				 * 使用了jquery的事件
				 */
				$('#dialog-content').html(result);
				// 去除进度信息
				dialogcontent.style.backgroundImage = '';
				dialogcontent.style.backgroundPosition = 'bottom right';
			}
			// 执行回调
			if(typeof(successCallBack) != 'undefined' && successCallBack.constructor == Function){
				successCallBack(result);
			}
   		}
   });
  /***********************************************
   * 添加
   ***********************************************/
   // 如果是IE时，会出现dialog的title与content的width是不一样的，所以此时取title的width为content的width
   if(document.all){
   	dialogcontent.style.width = dialogheader.offsetWidth + 'px';
   }
   /***********************************************
   * 添加
   ***********************************************/
  	document.getElementById('dialog-title').style.display = "";
  	dialog.style.display = "";
    document.getElementById('dialog-mask').style.display = "";
    document.getElementById('dialog-close').display = "";
  $("#dialog-mask").bgiframe();
}

// hide the dialog box //
// 关闭窗口之前的回调方法
function hideDialog() {
	/**
	 * 把层也隐藏
	 */
  var dialog = document.getElementById('dialog');
	if(dialog.style.display == ''){
		dialog.style.display = 'none';
  	}
  var dialogmask = document.getElementById('dialog-mask');
  if(dialogmask.style.display == ''){
  	dialogmask.style.display = 'none';
  }
}
